<ix-modal-header
  [requiredRoles]="requiredRoles"
  [title]="'FTP' | translate"
  [loading]="isFormLoading()"
></ix-modal-header>

<mat-card class="card">
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()">
      <div class="form-columns">
        <div class="column">
          <ix-fieldset [title]="'General Options' | translate">
            <ix-input
              formControlName="port"
              type="number"
              [label]="'Port' | translate"
              [required]="true"
              [tooltip]="helptext.portTooltip | translate"
            ></ix-input>

            <ix-input
              formControlName="clients"
              type="number"
              [label]="'Clients' | translate"
              [required]="true"
              [tooltip]="helptext.clientsTooltip | translate"
            ></ix-input>

            <ix-input
              formControlName="ipconnections"
              type="number"
              [label]="'Connections' | translate"
              [required]="true"
              [tooltip]="helptext.ipconnectionsTooltip | translate"
            ></ix-input>

            <ix-input
              formControlName="loginattempt"
              type="number"
              [label]="'Login Attempts' | translate"
              [required]="true"
              [tooltip]="helptext.loginattemptTooltip | translate"
            ></ix-input>

            <ix-input
              formControlName="timeout_notransfer"
              type="number"
              [label]="'Notransfer Timeout' | translate"
              [required]="true"
              [tooltip]="helptext.timeoutNotransferTooltip | translate"
            ></ix-input>

            <ix-input
              formControlName="timeout"
              type="number"
              [label]="'Timeout' | translate"
              [required]="true"
              [tooltip]="helptext.timeoutTooltip | translate"
            ></ix-input>
          </ix-fieldset>

          @if (isAdvancedMode) {
            <ix-fieldset [title]="'Access' | translate">
              <ix-checkbox
                formControlName="defaultroot"
                [label]="'Always Chroot' | translate"
                [tooltip]="helptext.defaultrootTooltip | translate"
              ></ix-checkbox>

              <ix-checkbox
                formControlName="onlyanonymous"
                [label]="'Allow Anonymous Login' | translate"
                [tooltip]="helptext.onlyanonymousTooltip | translate"
              ></ix-checkbox>

              @if (isAnonymousLoginAllowed$ | async) {
                <ix-explorer
                  formControlName="anonpath"
                  [label]="'Path' | translate"
                  [tooltip]="helptext.anonpathTooltip | translate"
                  [nodeProvider]="treeNodeProvider"
                  [canCreateDataset]="true"
                ></ix-explorer>
              }

              <ix-checkbox
                formControlName="onlylocal"
                [label]="'Allow Local User Login' | translate"
                [tooltip]="helptext.onlylocalTooltip | translate"
              ></ix-checkbox>

              <ix-checkbox
                formControlName="ident"
                [label]="'Require IDENT Authentication' | translate"
                [tooltip]="helptext.identTooltip | translate"
              ></ix-checkbox>

              <ix-permissions
                formControlName="filemask"
                [label]="'File Permissions' | translate"
                [tooltip]="helptext.filemaskTooltip | translate"
              ></ix-permissions>

              <ix-permissions
                formControlName="dirmask"
                [label]="'Directory Permissions' | translate"
                [tooltip]="helptext.dirmaskTooltip | translate"
              ></ix-permissions>
            </ix-fieldset>
          }
        </div>
        @if (isAdvancedMode) {
          <div class="column">
            <ix-fieldset [title]="ignoreTranslation('TLS')">
              <ix-checkbox
                formControlName="tls"
                [label]="'Enable TLS' | translate"
                [tooltip]="helptext.tlsTooltip | translate"
              ></ix-checkbox>

              @if (isTlsEnabled$ | async) {
                <ix-with-manage-certificates-link>
                  <ix-select
                    formControlName="ssltls_certificate"
                    [label]="'Certificate' | translate"
                    [tooltip]="helptext.ssltlsCertificateTooltip | translate"
                    [required]="true"
                    [options]="certificates$"
                  ></ix-select>
                </ix-with-manage-certificates-link>

                <ix-select
                  formControlName="tls_policy"
                  [label]="'TLS Policy' | translate"
                  [tooltip]="helptext.tlsPolicyTooltip | translate"
                  [options]="tlsPolicyOptions$"
                ></ix-select>

                <ix-checkbox
                  formControlName="tls_opt_allow_client_renegotiations"
                  [label]="'TLS Allow Client Renegotiations' | translate"
                  [tooltip]="helptext.tlsAllowClientRenegotiationsTooltip| translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_allow_dot_login"
                  [label]="'TLS Allow Dot Login' | translate"
                  [tooltip]="helptext.tlsAllowDotLoginTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_allow_per_user"
                  [label]="'TLS Allow Per User' | translate"
                  [tooltip]="helptext.tlsAllowPerUserTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_common_name_required"
                  [label]="'TLS Common Name Required' | translate"
                  [tooltip]="helptext.tlsCommonNameRequiredTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_enable_diags"
                  [label]="'TLS Enable Diagnostics' | translate"
                  [tooltip]="helptext.tlsEnableDiagsTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_export_cert_data"
                  [label]="'TLS Export Certificate Data' | translate"
                  [tooltip]="helptext.tlsExportCertDataTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_no_empty_fragments"
                  [label]="'TLS No Empty Fragments' | translate"
                  [tooltip]="helptext.tlsNoEmptyFragmentsTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_no_session_reuse_required"
                  [label]="'TLS No Session Reuse Required' | translate"
                  [tooltip]="helptext.tlsNoSessionReuseRequiredTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_stdenvvars"
                  [label]="'TLS Export Standard Vars' | translate"
                  [tooltip]="helptext.tlsStdenvvarsTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_dns_name_required"
                  [label]="'TLS DNS Name Required' | translate"
                  [tooltip]="helptext.tlsDnsNameRequiredTooltip | translate"
                ></ix-checkbox>

                <ix-checkbox
                  formControlName="tls_opt_ip_address_required"
                  [label]="'TLS IP Address Required' | translate"
                  [tooltip]="helptext.tlsIpAddressRequiredTooltip | translate"
                ></ix-checkbox>
              }
            </ix-fieldset>
            <ix-fieldset [title]="'Other Options' | translate">
              <ix-input
                formControlName="passiveportsmin"
                type="number"
                [label]="'Minimum Passive Port' | translate"
                [tooltip]="helptext.passiveportsminTooltip | translate"
              ></ix-input>

              <ix-input
                formControlName="passiveportsmax"
                type="number"
                [label]="'Maximum Passive Port' | translate"
                [tooltip]="helptext.passiveportsmaxTooltip | translate"
              ></ix-input>

              <ix-checkbox
                formControlName="fxp"
                [label]="'Enable FXP' | translate"
                [tooltip]="helptext.fxp_tooltip | translate"
              ></ix-checkbox>

              <ix-checkbox
                formControlName="resume"
                [label]="'Allow Transfer Resumption' | translate"
                [tooltip]="helptext.resumeTooltip | translate"
              ></ix-checkbox>

              <ix-checkbox
                formControlName="reversedns"
                [label]="'Perform Reverse DNS Lookups' | translate"
                [tooltip]="helptext.reversednsTooltip | translate"
              ></ix-checkbox>

              <ix-input
                formControlName="masqaddress"
                [label]="'Masquerade Address' | translate"
                [tooltip]="helptext.masqaddressTooltip | translate"
              ></ix-input>

              <ix-textarea
                formControlName="banner"
                [label]="'Display Login' | translate"
                [tooltip]="helptext.bannerTooltip | translate"
              ></ix-textarea>

              <ix-textarea
                formControlName="options"
                [label]="'Auxiliary Parameters' | translate"
                [tooltip]="helptext.optionsTooltip | translate"
              ></ix-textarea>
            </ix-fieldset>

            <ix-fieldset [title]="'Bandwidth' | translate">
              <ix-input
                formControlName="localuserbw"
                [label]="helptext.localuserbwLabel | translate"
                [tooltip]="helptext.userbwTooltip | translate"
                [format]="iecFormatter.memorySizeFormatting"
                [parse]="kibParser"
              ></ix-input>

              <ix-input
                formControlName="localuserdlbw"
                [label]="'Local User Download Bandwidth' | translate"
                [tooltip]="helptext.userbwTooltip | translate"
                [format]="iecFormatter.memorySizeFormatting"
                [parse]="kibParser"
              ></ix-input>

              <ix-input
                formControlName="anonuserbw"
                [label]="'Anonymous User Upload Bandwidth' | translate"
                [tooltip]="helptext.userbwTooltip | translate"
                [format]="iecFormatter.memorySizeFormatting"
                [parse]="kibParser"
              ></ix-input>

              <ix-input
                formControlName="anonuserdlbw"
                [label]="'Anonymous User Download Bandwidth' | translate"
                [tooltip]="helptext.userbwTooltip | translate"
                [format]="iecFormatter.memorySizeFormatting"
                [parse]="kibParser"
              ></ix-input>
            </ix-fieldset>
          </div>
        }
      </div>

      <ix-form-actions>
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="submit"
          color="primary"
          ixTest="save"
          [disabled]="form.invalid || isFormLoading()"
        >
          {{ 'Save' | translate }}
        </button>

        @if (isAdvancedMode) {
          <button
            mat-button
            type="button"
            ixTest="toggle-advanced-options"
            (click)="onToggleAdvancedOptions()"
          >
            {{ 'Basic Options' | translate }}
          </button>
        } @else {
          <button mat-button type="button" ixTest="toggle-advanced-options" (click)="onToggleAdvancedOptions()">
            {{ 'Advanced Options' | translate }}
          </button>
        }
      </ix-form-actions>
    </form>
  </mat-card-content>
</mat-card>
